import requests

from Constances import UserAgent

url = "https://www.pearvideo.com/video_1771601"
contId = url.split("_")[1]

headers = {
    # "Cookie": 'aliyungf_tc=8b1da83a807131b7303da9c59e8caa3c27a9f2e9ecfcf1a1fff54156b576586e; acw_tc=2f6fc10316789360034264955eb19d5183a25654bd9f3285a6e71e7e3537fe; JSESSIONID=C58BE81D14C9C4841136D0B9F85E1A26; PEAR_UUID=cbe5c1de-7c50-4609-8e8c-073c40985da2; _uab_collina=167893600523004998119504; Hm_lvt_9707bc8d5f6bba210e7218b8496f076a=1678936006; Hm_lpvt_9707bc8d5f6bba210e7218b8496f076a=1678936590; p_h5_u=A60097B7-EFA4-41F8-A6CF-66D9405D13C7; SERVERID=a6169b2e0636a71b774d6641c064eb8c|1678936772|1678936003',
    # "User-Agent": UserAgent,
    # 防盗链：溯源上一级连接
    "Referer": "https://www.pearvideo.com/video_1771601"
}

videoStatusUrl = f"https://www.pearvideo.com/videoStatus.jsp?contId={contId}&mrd=0.5332418075782082"
resp = requests.get(url=videoStatusUrl, headers=headers)
print(resp.json())
dic = resp.json()
srcUrl = dic['videoInfo']['videos']['srcUrl']
systemTime = dic['systemTime']

# 真：https://video.pearvideo.com/mp4/short/20220920/cont-1771601-15926900-hd.mp4
# 假：https://video.pearvideo.com/mp4/short/20220920/1678936772904-15926900-hd.mp4
realSrc = srcUrl.replace(systemTime, f'cont-{contId}')
print(realSrc)

# 下载视频
with open("test.mp4", mode="wb") as f:
    f.write(requests.get(url=realSrc).content)